package com.liukaixin.product.navi;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.Objects;

/**
 * Created by liukaixin on 16/10/13.
 */

public class LoginActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText phoneNumberEdit;
    private EditText passwordEdit;
    private EditText licensePlateNumbeEdit;

    private String phoneNumber;
    private String password;
    private String licensePlate;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_login);

        phoneNumberEdit = (EditText) findViewById(R.id.phone_number_edit);
        passwordEdit = (EditText) findViewById(R.id.password_edit);
        licensePlateNumbeEdit = (EditText) findViewById(R.id.license_plate_number_edit);
        Button loginButton = (Button) findViewById(R.id.login_one_press_button);
        loginButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        phoneNumber = phoneNumberEdit.getText().toString().trim();
        password = passwordEdit.getText().toString().trim();
        licensePlate = licensePlateNumbeEdit.getText().toString().trim();

        if (phoneNumber.isEmpty()) {
            emptyToast("手机号");
        } else if (password.isEmpty()) {
            emptyToast("密码");
        } else if (licensePlate.isEmpty()) {
            emptyToast("车牌号");
        } else {
            if (phoneNumber.equals("13126895798")
                    && password.equals("123456")
                    && licensePlate.equals("50026")) {
                toLoginSuccessActivity();
                finish();
            } else {
                Toast.makeText(LoginActivity.this,
                        "用户名/密码/车牌号错误", Toast.LENGTH_SHORT).show();
            }
        }
    }

    private void emptyToast(String msg) {
        Toast.makeText(LoginActivity.this, msg + "不能为空", Toast.LENGTH_SHORT).show();
    }


    private void toLoginSuccessActivity() {
        Intent slide = new Intent(this, MainActivity.class);
        startActivity(slide);
    }

}
